/*
 * 登出
 * @date 2016/05/07
 */

$("#logout").click(function () {
    layer.confirm('确定要退出吗？', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        logout();
    });
});

//登出
function logout() {
    $.ajax({
        url: "/login/logout",
        dataType: 'json',
        type: 'post',
        data: JSON.stringify({'""': '""'}),
        success: function (data) {
            if (data.status == 0) {
                window.location = "/login/index";
            } else {
                bbx_alert_error(data.message);
            }
        },
        error: function (data) {
            console.log(data);
            bbx_alert_error(data.message);
        }
    });
}

$(function () {
    // 获取当前时间
    var currTime = new Date();
    var year = currTime.getYear() + 1900;
    var month = currTime.getMonth() + 1;
    var date = currTime.getDate();
    var week = currTime.getDay();
    var week_day;
    if (week == 1) {
        week_day = "星期一";
    }
    if (week == 2) {
        week_day = "星期二";
    }
    if (week == 3) {
        week_day = "星期三";
    }
    if (week == 4) {
        week_day = "星期四";
    }
    if (week == 5) {
        week_day = "星期五";
    }
    if (week == 6) {
        week_day = "星期六";
    }
    if (week == 0) {
        week_day = "星期日";
    }
    var colorHtml = year + '年' + month + '月' + date + '日' + ' ' + week_day;
    $('.hd-time').html(colorHtml);
});

////判断用户权限 显示相应菜单项
//$(document).ready(function(){
//    var role = $('#user').attr('role');
//    $('.sub-list li').each(function(){
//        $(this).hide();
//        var roleArr = $(this).data('role');
//        for(var i=0; i<roleArr.length; i++){
//            if(role == roleArr[i]){
//                $(this).show();
//                break;
//            }
//        }
//    });
//    $('.sub-list').each(function(){
//        var showFlag = false;
//        $(this).find('li').each(function(){
//            if($(this).css('display')!="none"){
//                showFlag = true;
//                return;
//            }
//        });
//        showFlag ? $(this).parents('li.sidebar-item').show(): $(this).parents('li.sidebar-item').hide()
//    });
//});

//根据角色管理权限配置 显示相应菜单项
 $(document).ready(function () {
     var authority = $('#user').attr('authority');   //"["*"]", "["1","1-1","1-2","2","2-1","3","3-2"]"
     //字符串转数组格式
     var _authority = JSON.parse(authority);

     if (_authority[0] == "*") {
         $('.sn-item').show();
     } else {
         $('.sn-item').each(function () {
             $(this).hide();
             var sn = $(this).data('sn');
             for (var i = 0; i < _authority.length; i++) {
                 if (_authority[i] == sn) {
                     $(this).show();
                     break;
                 }
             }
         });
     }
 });